package com.seteam.collabcrossword;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

public class ObservableQueue<E> extends ConcurrentLinkedQueue<E> {
    private List<QueueObserver<E>> observerList;

    public ObservableQueue() {
        super();
        observerList = new ArrayList<QueueObserver<E>>();
    }

    public void registerObserver(QueueObserver<E> observer) {
        observerList.add(observer);
    }

    @Override
    public boolean add(final E element) {
        boolean result = super.add(element);
        if (result) {
            for (final QueueObserver<E> observer : observerList) {
                observer.onAdd(element);
            }
        }
        return result;
    }
}
